function Ndkhpshz(){
	this.form=this.InitForm();
	this.tab=this.InitEleUI();
	//this.table=this.InitTable();
	
	$("#year").val($("#hidyear").val());
	this.form.render('select');
	
	this.currenttabindex=0;
	this.InitGrid();
	
	this.table=this.InitTableByBt();
	this.InitOrg();
}

Ndkhpshz.prototype.InitOrg = function() {
	var comboboxm=$("#orgid").ligerComboBox({
		valueField : 'orgid',
		textField : 'orgname',
		selectBoxWidth : 250,
		selectBoxHeight:250,
		treeLeafOnly:false,
		valueFieldID:"hid",
		tree: {url : '../common/get_org_list?orgtype=0',
			checkbox: false, 
			nodeWidth:150,
			ajaxType: 'get', 
			idFieldName: 'orgid',
			textFieldName:"orgname",
			idField:"orgid",
        	parentIDField:"orgparentid"
		},
		onSelected : function(orgid, orgname) {// id为空值，name为选择的值
			$("#hidorgid").val(orgid);
			vNdkhpshz.searchtable();
		},
		width : 250
	});
	return comboboxm;
}

Ndkhpshz.prototype.InitGrid=function (){
	var year=$("#year").val();
	
	
	var _this = this;
    window.liger.remove("listorg");
    if (_this.grid == null) {
        _this.grid = $("#listorg").ligerGrid({
            columns: [
                      //{ display: '序号', width: 80, name: 'rowNum' },
                     { display: '机构名称', width:250, align:'left',name: 'orgname',id:"orgname"},
                     { display: '年份', width: 100, name: 'year' },
                     { display: '参加考核人数', width: 100, name: 'usercount' },
                     { display: '状态', width: 100, name: 'status', render: function (rowdata, rowindex, value) { 
                    	 if(rowdata.status==1){
                    		 return "提交";
                    	 }
                    	 else if(rowdata.status==2){
                    		 return "归档";
                    	 }
                    	 else if(rowdata.status==3){
                    		 return "驳回";
                    	 }
                     } },
                     { display: '说明', width: 120, name: 'remark' },
                     
                     {display: '操作', width: 100, name: 'userid', render: function (rowdata, rowindex, value) {
                    	var html='';
                    	
                    		if(rowdata.status==1){
                            	html+='<img class="btn-img" onclick="vNdkhpshz.BmTiJiao('+rowdata.orgstatustjid+',2,'+rowdata.orgid+','+rowdata.year+')" src="'+ctxStatic+'/images/button/guidang.png" lay-event="guidang" alt="归档" title="归档">';
                            	html+='<img class="btn-img" onclick="vNdkhpshz.BmTiJiao('+rowdata.orgstatustjid+',3,'+rowdata.orgid+','+rowdata.year+')" src="'+ctxStatic+'/images/button/bohui.png" lay-event="bohui" alt="驳回" title="驳回">';
                        		
                        	}
                    		if(rowdata.status==0||rowdata.status==1||rowdata.status==2||rowdata.status==3){
                        	html+=' <img class="btn-img" src="'+ctxStatic+'/images/button/detail.png" onclick="vNdkhpshz.ChangeTab(1,'+rowdata.orgid+')"  alt="详情" title="详情"> ';
                    		}
                    	
                    	return html;
                     }}
            ],
            pageSize: 30,
            url: "get_list_org" + '?time=' + new Date().getTime(),
            delayLoad: false,            //初始化时是否加载,为true时,不加载,为false时,则加载
            sortName: null,
            dataAction: 'server',
            parms: {
                Method: "",
                year: year
            },
            sortOrder: null,
            sourceObj: _this.grid,
            root: 'items',                       //数据源字段名
            record: 'countRecord',                    //数据源记录数字段名
            pageParmName: 'CurrentPage',               //页索引参数名，(提交给服务器)
            pagesizeParmName: 'PageSize',        //页记录数参数名，(提交给服务器)
            data: {},
            width: "100%",
            height: '100%',
            heightDiff: 0,
            rowHeight:28,
            onSuccess: function (rowdata, rowindex) { if (rowdata.status > 0) { alert(rowdata.msg) } },
            alternatingRow: true,
            border: 0,
            usePager:false,
            tree:{
            	columnId:"orgname",
            	idField:"orgid",
            	parentIDField:"orgparentid"
            	
            }
        })
    }
}

Ndkhpshz.prototype.InitForm=function(){
	var form;
	layui.use('form', function(){
       form = layui.form; //只有执行了这一步，部分表单元素才会自动修饰成功
       form.on('select(year)', function (data) { 
    	   vNdkhpshz.InitPage();
       });
       
       form.on('select(khjg)', function (data) { 
    	   vNdkhpshz.searchtable();
       });
       
       
       
	   form.render();
	});  
	return form;
}


Ndkhpshz.prototype.InitEleUI=function(){
	var element;
	var _this=this;
	layui.use('element', function(){
       element=layui.element;
       
       element.on('tab(tabcontent)', function(data){
    	  vNdkhpshz.currenttabindex=data.index;
    	  if(data.index==1){
    		  _this.InitTableByBt();
    	  }
    	  if(data.index==0){
    		  $("#hidorgid").val("");
    	  }
	}); 
	})
	return element;
}

Ndkhpshz.prototype.InitTableByBt=function (){
	var table;
	var _this=this;
	layui.use('table', function() {
	    table = layui.table;
	    table.init('uatmzpdsummary', {
			height : $(window).height() - 135
			,url : 'get_ndkh_detail_list' // 数据接口
			,page : true // 开启分页
			,limit : 40
			,limits:[20,40,80,100]
			,id: 'uatmzpdsummary'
			,method:"post"
				,request:{
					type:'post'
				}
				,where:{
					year: $("#year").val(),
					szdw:$("#hidorgid").val(),
					realname:$("#realname").val(),
					khjg:$("#khjg").val()
					}
			    ,done: function(res, page, count){
			    
			    	
	               
			    }
				
				
		  });
	    
	    
	    //监听工具条
	    table.on('tool(uatmzpdsummary)', function(obj){
	    	
	      var data = obj.data;
	      if(obj.event === 'edit'){
	    	  vNdkhpshz.opentz(data.ndkhpsid);
	      } 
	    });
	    
	    
	})
	
	return table;
	
	

}

Ndkhpshz.prototype.opentz=function(ndkhpsid){
	top.mylayui.open({
        type: 2,
        title: '调整年度考核结果',
        shadeClose: true,
        shade: 0.5,
        area: ['600px', '300px'],
        content: 'ndkhps/ndkhtb_tz?ndkhpsid='+ndkhpsid
      });
	
}

Ndkhpshz.prototype.addresult=function(result,msg){
	if(result>0){
		top.mylayui.msg('操作成功', {icon: 1});
		top.mylayui.closeAll('iframe');
		//vUser.searchtable();
		vNdkhpshz.searchtable();
	}
	else{
		if(msg){
			top.mylayui.msg(msg, {icon: 0});
		}else{
			top.mylayui.msg('操作失败', {icon: 0});
		}
	}
}

Ndkhpshz.prototype.addresultorg=function(result,msg){
	if(result>0){
		top.mylayui.msg('操作成功', {icon: 1});
		top.mylayui.closeAll('iframe');
		//vUser.searchtable();
		vNdkhpshz.searchlist();
	}
	else{
		if(msg){
			top.mylayui.msg(msg, {icon: 0});
		}else{
			top.mylayui.msg('操作失败', {icon: 0});
		}
	}
}

Ndkhpshz.prototype.searchtable=function(){
	this.table.reload('uatmzpdsummary', { 
		  page: {
	        curr: 1 //重新从第 1 页开始
	      }
	    ,where: {  
	    	year: $("#year").val(),
			szdw:$("#hidorgid").val(),
			realname:$("#realname").val(),
			khjg:$("#khjg").val()
	    }  
	}); 
}


Ndkhpshz.prototype.deleteentity=function(mzpdid){
	$.ajax({
		type:"POST",
		url:"delete_mzpd",
		data:{mzpdid:mzpdid},
		beforeSend:function(XHR){
			
		},
		success:function(data){
			data=eval('('+data+')');
			if(data.result>0){
				top.mylayui.msg(data.msg, {icon: 1});
				document.location.reload();
			}
			else{
				top.mylayui.msg(data.msg, {icon: 0});
			}
		},
		complete:function(XHR){
			
		},
		error:function(){
			
		}
	});
}


Ndkhpshz.prototype.exportentity=function(){
	top.ShowZheZhao();
	$.ajax({
		type:"POST",
		url:"export_excel_all",
		data:{year: $("#year").val(),
			szdw:$("#hidorgid").val(),
			realname:$("#realname").val(),
			khjg:$("#khjg").val()},
		beforeSend:function(XHR){
			
		},
		success:function(data){
			data=eval('('+data+')');
			if(data.result>0){
				//top.mylayui.msg('导出成功', {icon: 1});
				//document.location.reload();
				window.open(data.msg,'_self');
				
			}
			else{
				top.mylayui.msg(data.msg, {icon: 0});
			}
			top.ShowZheZhao();
		},
		complete:function(XHR){
			top.mylayui.closeAll('loading');
		},
		error:function(){
			
		}
	});
}

Ndkhpshz.prototype.ChangeTab=function(index,orgid){
	this.tab.tabChange('tabcontent', index);
	if(orgid){
		if(index==1){
			$("#hidorgid").val(orgid);
			vNdkhpshz.InitTableByBt();
		}
		else{
			//vUserUATMzpdHz.InitIfream(mzpdid);
		}
		
	}
	
}
Ndkhpshz.prototype.InitIfream=function(mzpdid){
	
	$("#getdata").attr("src","user_usasstemp_mzpd_detail?mzpdid="+mzpdid);
}


Ndkhpshz.prototype.searchlist = function () {
	var year=$("#year").val();
    this.grid.setOptions({
        newPage: 1, parms: {
            Method: "",
            year: year
        }
    });
    this.grid.loadData();
}

Ndkhpshz.prototype.InitPage=function(){
	if(vNdkhpshz.currenttabindex==0){
		vNdkhpshz.searchlist();
	}
	else if(vNdkhpshz.currenttabindex==1){
		vNdkhpshz.searchtable();
	}else{
		 //vUserUsAssTempLd.InitIfream();
	}
}

Ndkhpshz.prototype.BmTiJiao=function(orgstatustjid,status,orgid,year){
	var title="归档";
	if(status==3){
		title="驳回";
	}
	
	top.mylayui.open({
        type: 2,
        title: title,
        shadeClose: true,
        shade: 0.5,
        area: ['500px', '250px'],
        content: 'ndkhps/ndkh_status?orgstatustjid='+orgstatustjid+"&status="+status+"&orgid="+orgid+"&year="+year
      });
	
	
}







var vNdkhpshz=null;
$(function(){
	vNdkhpshz=new Ndkhpshz();
})